import { MockMethod } from "vite-plugin-mock";
import { Random } from "mockjs";
function creataDataItem(data = {}) {
  const item = {
    id: "",
    title: "首页",
    icon: "",
    path: "",
    order: 1,
    file: "",
    shows: true,
    pid: "",
    isIframe: "",
    url: "",
    keepAlive: false,
    tabHidden: false,
    tabFix: false,
    httpFile: "",
    permission: [],
  };
  for (const itemKey in item) {
    if (data[itemKey] || data[itemKey] === false) {
      item[itemKey] = data[itemKey];
    }
  }
  return item;
}
export default [
  {
    url: "/login",
    method: "post",
    response: () => {
      return {
        code: 1,
        data: {
          username: "管理员",
          id: Random.id(),
          accessToken: Random.id(),
          expiresTime: Random.now(),
        },
      };
    },
  },
  {
    url: "/register",
    method: "post",
    response: () => {
      return {
        code: 1,
        data: {
          id: Random.id(),
          expiresTime: Random.now(),
        },
      };
    },
  },
  {
    url: "/userInfo",
    method: "post",
    response: () => {
      return {
        code: 1,
        data: {
          username: "管理员",
          permission: ["sys:permission:admin", "sys:permission:web"],
        },
      };
    },
  },
  {
    url: "/menus",
    method: "post",
    response: () => {
      return {
        code: 1,
        data: [
          creataDataItem({
            id: 1000,
            title: "首页",
            path: "/home",
            file: "/view/home/index.vue",
            icon: "HomeOutline",
            keepAlive: true,
            tabFix: true,
            order: 100,
          }),
          creataDataItem({
            id: 2000,
            title: "用户管理",
            icon: "CubeOutline",
            file: "/view/user/index.vue",
            path: "/user",
            tabFix: true,
            order: 200,
          }),
          creataDataItem({
            id: 2001,
            title: "编辑用户",
            pid: 2000,
            file: "/view/user/edit.vue",
            path: "/user/edit/:id",
            icon: "",
            shows: false,
          }),
          creataDataItem({
            id: 2002,
            title: "新增用户",
            pid: 2000,
            file: "/view/user/add.vue",
            path: "/user/add",
            icon: "",
            shows: false,
          }),
          creataDataItem({
            id: 3000,
            title: "背景大图",
            icon: "SettingsOutline",
            file: "/view/background/index.vue",
            path: "/background",
            tabFix: true,
            order: 300,
          }),
          creataDataItem({
            id: 4000,
            title: "精选图片",
            icon: "FileTrayOutline",
            file: "/view/good-picture/index.vue",
            path: "/good-picture",
            tabFix: true,
            order: 400,
          }),
          creataDataItem({
            id: 5000,
            title: "所有图片",
            icon: "FileTrayOutline",
            file: "/view/all-picture/index.vue",
            path: "/all-picture",
            tabFix: true,
            order: 500,
          }),
          // creataDataItem({
          //   id: 6000,
          //   title: "上传照片处理",
          //   icon: "FileTrayOutline",
          //   file: "/view/upload-picture/index.vue",
          //   path: "/upload-picture",
          //   tabFix: true,
          //   order: 600,
          // }),
        ],
      };
    },
  },
] as MockMethod[];
